<?php

require_once '../../PUBLIC.php';
require '../../core/class/PayBase.php';
include 'WeixinPay.php';

/**
 * 处理支付的类
 * 继承自我的类
 * 调用了微信的类
 */
class ZhiFu extends PayBase
{

    public function __construct()
    {
        parent::__construct();
        $this->start();
        //$this->getDb();
    }

    //买水支付
    public function maiShui()
    {
        $fee = $this->db->getval('fee');
        $body = $this->db->getval('body');
        $openid = $this->db->getval('openid');
        $danhao = $this->db->getval('danhao');

        //调用付款
        $this->fukuanla(APPID, $openid, MCHID, KEY, $danhao, $body, $fee * 100);
    }

    //充值购买
    public function chongZhiPay()
    {

    }

    //预约购买
    public function yuYuePay()
    {

    }

    protected function updateUser($name, $phone, $openid)
    {
        //更新用户姓名和电话
        $query = "update " . QZ . "user set name = '{$name}',phone='{$phone}' where openid = '{$openid}' ";
        $this->db->exec($query);
    }

    //通用付款
    public function fukuanla($appid, $openid, $mch_id, $key, $out_trade_no, $body, $total_fee)
    {
        /*echo ' appid:' . $appid, ' openid:' . $openid, ' 商户号码:' . $mch_id, ' 商户密匙：' . $key, ' 商户订单：' . $out_trade_no, ' 支付主体:' . $body, ' 支付金额：' . $total_fee;
        exit();*/
        $weixinpay = new WeixinPay(
            $appid, $openid, $mch_id, $key,
            $out_trade_no, $body, $total_fee
        );
        $return = $weixinpay->pay();
        echo json_encode($return);
    }
}

new ZhiFu;
